<template>
  <div id="pageSuggest">
    <Menus title="投诉建议">
      <a @click="goback" href="javascript:void(0)">
        <div class="img_block">
          <img class="img_margin" src="static/img/icon_fanhui.png" alt="返回">
        </div>
        <span>返回</span>
      </a>
      <router-link to="/">
        <div class="img_block">
          <img class="img_margin" src="static/img/icon_fanhuishouye.png" alt="返回首页">
        </div>
        <span>返回首页</span>
      </router-link>
    </Menus>
    
    <div class="container">
      <div class="message-title">选择类别</div>
      <div class="choose-type">
        <div class="item" v-for="(item, index) in suggest_type" :key="'key-'+index" @click="suggest.com_type=item">
          <span :class="{on:item==suggest.com_type}">{{item}}</span>
        </div>
      </div>
      <div class="message-title">投诉建议</div>
      <div class="textarea">
        <textarea placeholder="内容" v-model="suggest.content"></textarea>
      </div>

      <div class="message-title">联系方式（选填）</div>
      <div class="input">
        <input type="text" placeholder="姓名" v-model="suggest.name" />
      </div>
      <div class="input">
        <input type="text" placeholder="联系电话" v-model="suggest.tell" />
      </div>

      <div class="content-block" @click="updateForm">
        <a class="button button-big" :class="{'button-fill':suggest.com_type && suggest.content, 'color-gray': !suggest.com_type || !suggest.content}">提交</a>
      </div>
      <Alert v-if="alert.show" :info="alert.info" :recall="alert.recall" @setClose="value=>alert.show=value" />
      </Dialogs>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.container {
  margin-top: 200px;
  .message-title {
    font-size: 28px;
    margin-bottom: 10px;
  }
  .choose-type {
    display: flex;
    padding: 15px 5px 0 15px;
    flex-wrap: wrap;
    .item {
      width: 33.33%;
      span {
        height: 36px;
        line-height: 36px;
        border: 1px solid #ccc;
        margin: 0 10px 10px 0;
        display: block;
        text-align: center;
        border-radius: 5px;
        background: #fff;
        font-size: 16px;
        color: #555;
        &.on {
          background: #2196f3;
          color: #fff;
          border-color: #2196f3;
        }
      }
    }
  }
  .textarea {
    padding-left: 15px;
    textarea {
      width: 80%;
      height: 200px;
      margin-bottom: 30px;
      border-radius: 10px;
      border: 1px solid #ccc;
      padding-left:20px;
      font-size: 20px;
    }
  }
  .input {
    padding-left: 15px;
    input {
      width: 80%;
      height: 50px;
      margin-bottom: 30px;
      border-radius: 10px;
      border: 1px solid #ccc;
      padding-left:20px;
      font-size: 20px;
    }
  }
  .content-block {
    background-color: rgb(61, 105, 189);
    margin: 0 auto;
    cursor: pointer;
    display: block;
    font-size: 28px;
    font-weight: 400;
    height: 72px;
    line-height: 72px;
    text-align: center;
    width: 280px;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    a {
      color: rgb(255, 255, 255);
    }
  }
}
</style>

<script>
import { suggest_type } from '@/config'
import Menus from '../components/Menu'
import Alert from '@/components/Alert'
export default {
  components: {
    Menus,
    Alert
  },
  data() {
    return {
      suggest_type,
      suggest: {
        com_type: '',
        content: '',
        tell: '',
        name: ''
      },
      alert: {
        // 提示内容
        show: false,
        info: '',
        recall: () => {}
      },
      scrollTop: 0
    }
  },
  methods: {
    goback() {
      this.$router.go(-1)
    },
    async updateForm() {
      if (!this.suggest.com_type) {
        this.alert.show = true
        this.alert.info = '请选择类别!'
        return
      }
      if (!this.suggest.content) {
        this.alert.show = true
        this.alert.info = '请填写投诉建议!'
        return
      }
      const res = await this.$post('/pufa/complain/add/', {
        com_type: this.suggest.com_type,
        content: this.suggest.content,
        tell: this.suggest.tell,
        name: this.suggest.name,
        code: this.$root.point.code
      })
      if (res.status === 1) {
        this.suggest.com_type = ''
        this.suggest.content = ''
        this.suggest.tell = ''
        this.suggest.name = ''
        this.alert.show = true
        this.alert.info = '提交成功'
      } else {
        this.alert.show = true
        this.alert.info = '提交失败！请重新提交'
      }
      console.log(res)
    }
  },
  mounted() {
    let dom = document.querySelector('.btn-suggest')
    dom.style.display = 'none'
  },
  beforeDestroy() {
    let dom = document.querySelector('.btn-suggest')
    dom.style.display = 'block'
  }
}
</script>